﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;

namespace demo.Web.AzureTables
{
    public class ContextBase :TableServiceContext
    {

                protected static CloudStorageAccount account;
        public static string TableName = "override_me_in_child_classes";

        static ContextBase()
        {
            account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
        }

        public ContextBase()
            : base(account.TableEndpoint.AbsoluteUri, account.Credentials)
        {
            this.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1));
            this.IgnoreMissingProperties = true;

        }

        public static void CreateTable(string TableName)
        {
            CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint.AbsoluteUri, account.Credentials);
            tableClient.CreateTableIfNotExist(TableName);
        }

    }
}